package com.allin.mall.user.entity.adapter;

import com.allin.mall.user.entity.User;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

@Slf4j
public class UserAdapter extends TypeAdapter<User> {

    @Override
    public void write(JsonWriter out, User value) throws IOException {
        out.beginObject();
//        out.name("code").value(value.getCode() + " - " + value.getId());
//        out.name("test").value("1 - 2 - 3");
//        out.value("110110");
        out.endObject();
    }

    @Override
    public User read(JsonReader in) throws IOException {
       /*
        in.beginObject();
        while (in.hasNext()) {
            log.info("read: name: {}, value: {}", in.nextName(), in.nextString());
        }
//        String[] nameParts = in.nextString().split(" ");
        in.endObject();
        */

        log.info(in.nextString());
        return new User();

    }
}
